package health.lm.com.component_base.pay.wxpay;

import android.content.Context;

import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import health.lm.com.component_base.pay.PaymentEntity;

import static health.lm.com.component_base.base.application.BaseApplication.AppId;

/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2018/12/29
 * 邮箱：15206394364@163.com
 * 介绍：
 * 修订：====================
 */
public class WxPayHelper {
    private static WxPayHelper wxPayHelper;

    private WxPayHelper() {
    }

    public static WxPayHelper getInstance() {
        if (wxPayHelper == null) {
            wxPayHelper = new WxPayHelper();
        }
        return wxPayHelper;
    }

    public void pay(Context context, PaymentEntity.WxBean param) {
        if (param == null) {
            return;
        }
        String appId = param.getAppid();
        IWXAPI api = WXAPIFactory.createWXAPI(context, null);
        api.registerApp(AppId);

        PayReq request = new PayReq();
        request.appId = appId;
        request.partnerId = param.getPartnerid();
        request.prepayId = param.getPrepayid();
        request.packageValue = param.getPackageX();
        request.nonceStr = param.getNoncestr();
        request.timeStamp = param.getTimestamp() + "";
        request.sign = param.getSign();
        api.sendReq(request);
    }
}
